package com.cheejee.goodscenter.module.response;

import java.util.List;

import static com.cheejee.goodscenter.util.ResponseCode.OK;

import com.cheejee.goodscenter.module.dto.SkuSnapshotDto;
import com.cheejee.goodscenter.util.ResponseCode;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author CARRY
 * @Date 2020年10月29日下午11:02:32
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class PageReponse extends BaseReponse {

	private static final long serialVersionUID = 7647183615675173368L;

	/**
	 * 页码，从1开始
	 */
	private int pageNum;
	/**
	 * 页面大小
	 */
	private int pageSize;
	/**
	 * 起始行
	 */
	private long startRow;
	/**
	 * 末行
	 */
	private long endRow;

	/**
	 * 总页数
	 */
	private int pages;
	

	/**
	 * @param code
	 * @param message
	 */
	public PageReponse(ResponseCode code, String message, Page<?> page) {
		super(code, message);
		this.pageNum = page.getPageNum();
		this.pageSize = page.getPages();
		this.startRow = page.getStartRow();
		this.endRow = page.getEndRow();
		this.pages = page.getPages();
		this.data = page;
	}
	
	public PageReponse(ResponseCode code, String message, PageInfo<?> page) {
		super(code, message);
		this.pageNum = page.getPageNum();
		this.pageSize = page.getPages();
		this.startRow = page.getStartRow();
		this.endRow = page.getEndRow();
		this.pages = page.getPages();
		this.data = page;
	}
	
	public static PageReponse ok(String message, Page<?> page) {
		return new PageReponse(OK, message, page);
	}
	
	public static PageReponse ok(Page<?> page) {
		return new PageReponse(OK, "查询完成", page);
	}

	/**
	 *
	 * @param querySkuSnapshot
	 * @return
	 */
	public static Object ok(PageInfo<?> info) {
		
		return new PageReponse(OK, "查询完成", info);
	}

}
